package com.situ.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import com.situ.bean.User;

public interface UserMapper {
	@Delete({ "delete from user", "where id = #{id,jdbcType=INTEGER}" })
	int deleteByPrimaryKey(Integer id);

	@Insert({ "insert into user ( username, ", "password, relname, ", "phone, head)",
			"values (#{username,jdbcType=VARCHAR}, ", "#{password,jdbcType=VARCHAR}, #{relname,jdbcType=VARCHAR}, ",
			"#{phone,jdbcType=VARCHAR}, #{head,jdbcType=VARCHAR})" })
	int insert(User record);

	@Select({ "select", "id, username, password, relname, phone, head", "from user",
			"where id = #{id,jdbcType=INTEGER}" })
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "username", property = "username", jdbcType = JdbcType.VARCHAR),
			@Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR),
			@Result(column = "relname", property = "relname", jdbcType = JdbcType.VARCHAR),
			@Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
			@Result(column = "head", property = "head", jdbcType = JdbcType.VARCHAR) })
	User selectByPrimaryKey(Integer id);

	@Select({ "select", "id, username, password, relname, phone, head", "from user" })
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "username", property = "username", jdbcType = JdbcType.VARCHAR),
			@Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR),
			@Result(column = "relname", property = "relname", jdbcType = JdbcType.VARCHAR),
			@Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
			@Result(column = "head", property = "head", jdbcType = JdbcType.VARCHAR) })
	List<User> selectAll();

	@Update({ "update user", "set username = #{username,jdbcType=VARCHAR},", "password = #{password,jdbcType=VARCHAR},",
			"relname = #{relname,jdbcType=VARCHAR},", "phone = #{phone,jdbcType=VARCHAR},",
			"head = #{head,jdbcType=VARCHAR}", "where id = #{id,jdbcType=INTEGER}" })
	int updateByPrimaryKey(User record);
}